
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/02/2012 11:34:45
-- Generated from EDMX file: C:\Source\CodePlex\wpstreaming\MockRadioStation\Data\MockRadioStationData.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [MockRadioStationDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ProgramPodcast]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Podcasts] DROP CONSTRAINT [FK_ProgramPodcast];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Podcasts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Podcasts];
GO
IF OBJECT_ID(N'[dbo].[Programs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Programs];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Programs'
CREATE TABLE [dbo].[Programs] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Presenters] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [StartTime] time  NOT NULL,
    [EndTime] time  NOT NULL,
    [AssociatedPodcastUrl] nvarchar(max)  NOT NULL,
    [AssociatedImageUrl] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Podcasts'
CREATE TABLE [dbo].[Podcasts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Keywords] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [PodcastUrl] nvarchar(max)  NOT NULL,
    [PublishedDate] datetime  NOT NULL,
    [ProgramId] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Programs'
ALTER TABLE [dbo].[Programs]
ADD CONSTRAINT [PK_Programs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Podcasts'
ALTER TABLE [dbo].[Podcasts]
ADD CONSTRAINT [PK_Podcasts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ProgramId] in table 'Podcasts'
ALTER TABLE [dbo].[Podcasts]
ADD CONSTRAINT [FK_ProgramPodcast]
    FOREIGN KEY ([ProgramId])
    REFERENCES [dbo].[Programs]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProgramPodcast'
CREATE INDEX [IX_FK_ProgramPodcast]
ON [dbo].[Podcasts]
    ([ProgramId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------